function FacebookDebug(){
	this.metrics;

	this.outAnalyseTagged;
	this.outAnalyseShare;
	this.outAnalyseComment;
	this.outAnalyseMutual;
	this.outAnalyseLike;

	var that = this;


	this.displayCoefs = function(n){
		console.log(this.metrics["likesCount"][n],
					this.metrics["sharesCount"][n],
					this.metrics["commentsCount"][n],
					this.metrics["taggedCount"][n],
					this.metrics["mutualCount"][n],
					this.metrics["inboxCount"][n]);
	};

	this.singleLikeAnalyse = function(userId){
		var myId = control.facebookId;
	
		var likeCount = 0;
		var shareCount = 0;			
		var list = this.outAnalyseLike;

		for(entry in list[userId].data){
			if(list[userId].data[entry].likes!=undefined){
				if(list[userId].data[entry].type==="photo") continue;
				for(like in list[userId].data[entry].likes.data){
					if( list[userId].data[entry].likes.data[like]==null ) continue;
					if( list[userId].data[entry].likes.data[like].id == myId ){
						likeCount+=1;
						break;
					}
				}
			}	

			if(list[userId].data[entry].shares!=undefined){
				shareCount+=1;
			}		
		}
		return [likeCount,shareCount];				
	}

	this.singleCommentAnalyse = function(userId){
		var myId = control.facebookId;
		var commentsCount = 0;	
		var list = this.outAnalyseComment;

		for(post in list[userId].data){
			if(list[userId].data[post].comments==undefined) continue;
			if(list[userId].data[post].comments.data==undefined) continue;

			for(comment in list[userId].data[post].comments.data){
				if(list[userId].data[post].comments.data[comment].from==undefined) continue

				if(list[userId].data[post].comments.data[comment].from.id==myId){				

					commentsCount+=1;										
					break;
				}
			}		
		}

		return commentsCount;		
	}

	this.jobTest = function(){
		var usersId = [];
		var j1 = new Job("FRIENDS TEST",100,function(r){
			var data = r[0].data;
			for(var i=0;i<data.length;i++){
				usersId.push(data[i].id);			
			}

			var j2 = new Job("Teste",100,function(){console.log("End");});
			j2.addAction( new PostBatchRequest(0,usersId,0,usersId.length) );
			j2.run();

		});

		j1.addAction( new FriendBatchRequest(0) );
		j1.run();
	}

	this.threadTest = function(){
		var messageJob = new Job("Message JOB",10,function(r){
			/*Cada r eh uma lista de objetos com as mensagens captadas para ua thread
				author_id: 100001521883282
				created_time: 1343839166
				message_id: "150993828359314_1"

				Fazer a analise em cima disso
			*/
			console.log("MESSAGE",r);

			var today = (new Date()).getTime();
			that.msgByAuthor = {};
			that.totalMsgByAuthor = {};
			that.lowestTime = today;
			for(req in r){
				//if(r[req].data.length==1) continue;
				var msg = r[req].data;
				for(m in msg){
					var author = msg[m].anon;	/*Author is included as an anonymous campus in the query*/
					var msgNumber = msg[m].message_id.split("_")[1];
					if(that.msgByAuthor[author]==undefined) that.msgByAuthor[author] = {};
					that.msgByAuthor[author][msgNumber] = msg[m].created_time;
					that.totalMsgByAuthor[author] = msgNumber;

					if(msg[m].created_time<that.lowestTime){
						that.lowestTime = msg[m].created_time;
					}
				}
			}


			that.diffByAuthor = {};			
			for(u in that.msgByAuthor){
				var totalMsg = that.totalMsgByAuthor[u];
				var pt1 = that.msgByAuthor[u][1];
				var pt9 = that.msgByAuthor[u][totalMsg];

				/*Higher Frequency Contact Equation - An rect equation*/
				var hfce = function(x){
					var newPt9 = (today-pt1)*totalMsg/(pt9-pt1);
					return pt1 + x*(newPt9-pt1)/totalMsg;
				};

				that.diffByAuthor[u]=0;
				for(point in that.msgByAuthor[u]){
					that.diffByAuthor[u]+= Math.abs( (that.msgByAuthor[u][point] - hfce(point)) );
				}

				that.diffByAuthor[u]/=(pt9-pt1+totalMsg);
			}
		});


		var threadJob = new Job("Thread JOB",10,function(r){
			if(control.debug) facebookDebug.outAnalyseThread = r;

			for(x in r[0].data){
				console.log("VARIOS",r[0].data[x].recent_authors);
				var author = null;
				for(n in r[0].data[x].recent_authors){
					if(r[0].data[x].recent_authors[n]!=control.facebookId){
						author = r[0].data[x].recent_authors[n];
						break;
					}
				}
				console.log(author);
				if(author!=null)
					messageJob.addAction( new MessageBatchRequest(0,author,r[0].data[x].thread_id,r[0].data[x].message_count) );
			}
			
			console.log("RUN");
			messageJob.run();
		});	

		threadJob.addAction( new ThreadBatchRequest(0) );
		threadJob.run();	
	}

}

var facebookDebug = new FacebookDebug;